﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace LogNet6.Sqlite;
/// <summary>
/// Sqlite日志扩展
/// </summary>
public static class SqliteLoggerServiceExtension
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="services"></param>
    /// <param name="connetionString">连接字符串</param>
    /// <returns></returns>
    public static IServiceCollection AddSqliteLogger(this IServiceCollection services, string connetionString)
    {
        services.AddLogging(ii =>
        {
            ii.ClearProviders();
            ii.Services.AddSingleton<ILoggerProvider, LoggerProvider>();
        });
        return services.AddSingleton(x => new SqliteLoggerProcessService(connetionString))
             .AddSingleton<ILoggerProcessor>(serviceProvider => serviceProvider.GetRequiredService<SqliteLoggerProcessService>())
             .AddSingleton<ISqliteLoggerProcessor>(serviceProvider => serviceProvider.GetRequiredService<SqliteLoggerProcessService>());

    }



}

